package com.unitech.order.config;

import com.unitech.order.constant.RabbitmqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
    @Bean
    DirectExchange exchange() {
        // 创建一个DirectExchange，持久化保存消息，不随消息队列关机而自动删除
        return new DirectExchange(RabbitmqConstant.EXCHANGE, true, false);
    }

    @Bean
    Queue queue() {
        return new Queue(RabbitmqConstant.QUEUE);
    }

    @Bean
    Binding bind() {
        return BindingBuilder.bind(queue())
                .to(exchange())
                .with(RabbitmqConstant.ROUTING_KEY);
    }
}
